package com.stylefeng.guns.modular.topic.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Topic;
import com.stylefeng.guns.modular.topic.service.ITopicService;

/**
 * 会议主题控制器
 *
 * @author fengshuonan
 * @Date 2018-07-29 22:56:33
 */
@Controller
@RequestMapping("/topic")
public class TopicController extends BaseController {

    private String PREFIX = "/topic/topic/";

    @Autowired
    private ITopicService topicService;

    /**
     * 跳转到会议主题首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "topic.html";
    }

    /**
     * 跳转到添加会议主题
     */
    @RequestMapping("/topic_add")
    public String topicAdd() {
        return PREFIX + "topic_add.html";
    }

    /**
     * 跳转到修改会议主题
     */
    @RequestMapping("/topic_update/{topicId}")
    public String topicUpdate(@PathVariable Integer topicId, Model model) {
        Topic topic = topicService.selectById(topicId);
        model.addAttribute("item",topic);
        LogObjectHolder.me().set(topic);
        return PREFIX + "topic_edit.html";
    }

    /**
     * 获取会议主题列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return topicService.selectList(null);
    }

    /**
     * 新增会议主题
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Topic topic) {
        topicService.insert(topic);
        return SUCCESS_TIP;
    }

    /**
     * 删除会议主题
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer topicId) {
        topicService.deleteById(topicId);
        return SUCCESS_TIP;
    }

    /**
     * 修改会议主题
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Topic topic) {
        topicService.updateById(topic);
        return SUCCESS_TIP;
    }

    /**
     * 会议主题详情
     */
    @RequestMapping(value = "/detail/{topicId}")
    @ResponseBody
    public Object detail(@PathVariable("topicId") Integer topicId) {
        return topicService.selectById(topicId);
    }
}
